package com.lagou.handler;

import com.lagou.pojo.RpcRequest;
import com.lagou.pojo.RpcResponse;
import com.lagou.service.UserServiceImpl;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class UserServerHandler extends ChannelInboundHandlerAdapter {


    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

        RpcRequest request = (RpcRequest) msg;
        if(request.getClassName().endsWith("UserService")){
            UserServiceImpl userService = new UserServiceImpl();
            String result = userService.sayHello(request.getParameterValue()[0].toString());
            RpcResponse response = new RpcResponse();
            response.setCode(200);
            response.setRequestId(request.getRequestId());
            response.setResult(result);
            ctx.writeAndFlush(response);
        }


    }
}
